package com.framework.demo.config;

import com.alibaba.fastjson.JSONObject;
import com.framework.demo.action.DemoAction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author LIN
 * @date 2021-05-10
 */
public class DemoInterceptor implements Interceptor {



    public Object getJson(){
        Map<String ,String> map = new TreeMap<>();

        map.put("a","1");
        map.put("b","2");
        map.put("c","3");
        return map;
    }

    @Override
    public void destroy() {
        System.out.println(this.getClass().getName()+":destroy");
    }

    @Override
    public void init() {
        System.out.println(this.getClass().getName()+":init");
    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        ActionContext invocationContext = invocation.getInvocationContext();
        DemoAction action = (DemoAction) invocation.getAction();
        action.setJson(getJson());
        return invocation.invoke();
//        return "success";
    }
}
